<template>
  <div class="charts" ref="charts"></div>
</template>

<script>
import * as echarts from "echarts";
export default {
  name: "barChart",
  mounted() {
    // 初始化echarts实例
    let barChart = echarts.init(this.$refs.charts);
    barChart.setOption({
      xAxis: {
        show: false,
        type: "category",
      },
      yAxis: {
        show: false,
      },
      series: [
        {
          type: "bar",
          data: [10, 39, 33, 47, 16, 44, 18, 9, 3, 7, 24],
        },
      ],
      tooltip: {
        show: true,
      },
      grid: {
        left: 0,
        top: 0,
        right: 0,
        bottom: 0,
      },
    });

    let timer = null;
    window.addEventListener("resize", () => {
      clearInterval(timer);
      timer = setTimeout(() => {
        barChart.resize();
      }, 50);
    });
  },
};
</script>

<style scoped>
.charts {
  width: 100%;
  height: 100%;
}
</style>
